<template>
	<view>
		<view style="background-color: #FFFFFF;">
			<cu-custom :isBack="true">
				<block slot="backText"></block>
				<block slot="content">产品上架</block>
			</cu-custom>
			<view class="cu-bar bg-white search fixed" :style="[{top:CustomBar + 'px'}]">
				<view class="search-form round">
					<text class="cuIcon-search"></text>
					<input @confirm="sub" v-model="asnId" type="text" placeholder="输入搜索的关键词" focus></input>
				</view>
				<view class="action" @click="toScan">
					<text class="cuIcon-scan" style="font-size: 56rpx;"></text>
				</view>
			</view>
			<scroll-view @scroll="scroll" scroll-y="true" class="indexes" :scroll-with-animation="true"
			 :enable-back-to-top="true" :style="[{height:'calc(100vh - '+ CustomBar + 'px)'}]" style="margin-top: 10%;">
				<!-- <view v-for="(item,index) in wh.inv"> -->
				<view class="padding" style="font-weight: 700; font-size: 16px;">总箱数：{{orderH.itotalboxnum}}  总托数：{{orderH.itotalpalletnum}}</view>
				<view class="padding" style="font-weight: 1000; font-size: 16px;">{{orderH.cvenname}}</view>
				<view class="cu-form-group">
					<view class="title">仓库</view>
					<picker @change="PickerChange" :value="indexs" :range="wArray">
						<view class="picker">
							{{indexs == -1?"请选择仓库！": wArray[indexs]}}
						</view>
					</picker>
				</view>
				<block v-for="(item,index) in orderC" :key="index">
					<view :id="'index_'+item.cinvcode">
						<view v-if="isShowAsn">
							<view class="padding" style="font-weight: 700; font-size: 16px;"><b style="color: #0081FF;font-size: 18px;">{{index+1}}.</b>{{item.cinvcode}} — {{item.cinvname}}</view>
							<form style="color: #0081FF;">
								<view class="scroll-view-item"  style="font-size: 32upx;">
									<view class="cu-form-group">
										<view class="title">订单编号：</view>
										<input :value="item.cpoid" placeholder="暂无数据" name="input" disabled="false"></input>
									</view>
									<view class="cu-form-group ">
										<view class="title">规格型号：</view>
										<input :value="item.cinvstd" placeholder="暂无数据" name="input" disabled="false"></input>
									</view>
									<view class="cu-form-group ">
										<view class="title">存货代码：</view>
										<input :value="item.cInvAddCode" placeholder="暂无数据" name="input" disabled="false"></input>
									</view>
									<view class="cu-form-group ">
										<view class="title" >送货数量：</view>
										<input :value="item.shQty" placeholder="暂无数据" name="input" disabled="false" ></input>
									</view>
									<view class="cu-form-group">
										<view class="title" style="color: red;font-weight: 1000;">到货数量：</view>
										<input v-model ="orderC[index].arrqty"  placeholder="暂无数据" type="number" ></input>
										<!-- @change="changeqty(index)" -->
									</view>
									<view class="cu-form-group">
										<view class="title">仓库</view>
										<picker :id="index" @change="PickerChange1" :value="item.cwindex" :range="wArray">
											<view class="picker">
												{{item.cwindex == -1?"请选择仓库！": wArray[item.cwindex]}}
											</view>
										</picker>
									</view>
									<view class="cu-form-group ">
										<view class="title">送货箱数：</view>
										<input :value="item.shNum" placeholder="暂无数据" name="input" disabled="false"></input>
									</view>
									<view class="cu-form-group ">
										<view class="title" style="color: red;font-weight: 1000;">到货箱数：</view>
										<input v-model ="orderC[index].arrnum"  placeholder="暂无数据" name="input" type="number"></input>
									</view>
									<view class="cu-form-group ">
										<view class="title">计量单位：</view>
										<input :value="item.cComUnitName"  placeholder="暂无数据" name="input" disabled="false"></input>
									</view>
									<view class="cu-form-group ">
										<view class="title">生产日期：</view>
										<input :value="item.dscDate" placeholder="暂无数据" name="input" disabled="false"></input>
									</view>
									<view class="cu-form-group ">
										<view class="title">批次编号：</view>
										<input :value="item.cpatchno" placeholder="暂无数据" name="input" disabled="false"></input>
									</view>
								</view>
							</form>
						</view>
					</view>
				</block>
				<!-- </view> -->
			</scroll-view>
		</view>
	</view>
</template>

<script>
	import {
		mapState
	} from 'vuex';
	export default {
		data() {
			return {
				CustomBar: this.CustomBar, //滚动定位用
				asnId:'',
				orderH: [],
				orderC: [],
				indexs:-1,
				wArray:[],
			}
		},
		computed: {
			...mapState(['hasLogin', 'userInfo', 'auditlist', 'corpCode']),
		},
		onShow(){
			uni.request({
				url:this.serverURL_a+'/bas/basWarehouse/treeData',
				data:{
					isShowCode : true,
					__sid:this.userInfo.sessionid
				},
				success:function(data){
					let ws= data.data;
					if(ws != undefined && ws.length > 0){
						this.wList = ws;
						for(var i=0;i<ws.length;i++){
							this.wArray.push(ws[i].name);
						}
						var ie = uni.getStorageSync("indexs");
						if(ie != undefined && ie != '' && this.wArray.length >= ie){
							this.indexs = ie;
						}
					}else{
						this.$api.msg('该账套没有仓库信息，不能到货！');
						return;
					} 
				}.bind(this),
				fail:function(){
					this.$api.msg('服务已停止,请稍后再试');
					return;
				}.bind(this),
			});
		},
		methods: {
			/**
			 * 仓库修改
			 */
			PickerChange(e) {
				for(var i=0;i<this.orderC.length;i++){
					if(this.orderC[i].cwindex == -1 || this.orderC[i].cwindex == this.indexs){
						this.orderC[i].cwindex = e.detail.value;
						this.orderC[i].cwhcode = this.wList[e.detail.value].id
					}
				}
				this.indexs = e.detail.value
				uni.setStorage({//缓存用户登陆状态
				    key: 'indexs',  
				    data: this.indexs  
				});
			},
			/**
			 * 扫码按钮扫码
			 */
			toScan() {
				uni.scanCode({
					onlyFromCamera: true,
					success: function(res) {
						this.asnId = res.result;
						this.loadData();
					}.bind(this)
				});
			},
			/**
			 * 扫码枪获取
			 */
			sub(){
				
			},
			/**
			 * 获取数据
			 */
			loadData(){
				
			},
		}
	}
</script>

<style>

</style>
